#ifndef RenderNodeImplC_DEFINED
#define RenderNodeImplC_DEFINED
#include "OHRenderNode.h"


//    class RenderNodeImpl {
//    public:
//        virtual ~RenderNodeImpl() = default;
//        virtual RenderNodeType getNodeType() = 0;
//        virtual void *getNodeObject() = 0;
//        virtual void initNode(void *UINode, OHRenderNode *selfNode) = 0;
//        virtual void prepareRedraw(OHRenderNode *node) = 0;
//        virtual void doRedraw(OHRenderNode *node) = 0;
//        virtual SkRect getNodeSize() = 0;
//        virtual void appendRootNode(std::shared_ptr<OHRenderNode> root) = 0;
//        virtual napi_value setLiveWithJs() { return nullptr; }
//        virtual napi_value getLocalJsObject() { return nullptr; }
//    };

class RenderNodeImplC : public OHRenderNode::RenderNodeImpl {
public:
    ~RenderNodeImplC() override;
    RenderNodeType getNodeType() override { return RenderNodeType::NODE_C; }
    void *getNodeObject() override;
    void initNode(void *UINode, OHRenderNode *selfNode) override;
    void doRedraw(OHRenderNode *node) override;
    SkRect getNodeSize() override;
    void appendRootNode(std::shared_ptr<OHRenderNode> root) override;
    void nodeDraw(OH_Drawing_Canvas *oh_canvas, OHRenderNode *selfNode) override;
    bool getPendingUnregisterNode() override { return fPendingUnregisterNode; } 
    void setPendingUnregisterNode() override { fPendingUnregisterNode = true; } 
    ArkUI_NodeHandle getCustomNode() override { return fCustomNode; }
    void setCustomNode(ArkUI_NodeHandle node) override { fCustomNode = node; }
    ArkUI_NodeHandle getExternalNode() override  { return fExternalNode; }
    void doInvalidate() override;

    static void FillOpsForBatch(NodeStatusModify::NodeBatchContext &ctx, const NodeStatusModify::NodeModifyInfo &info,
                                void *const (&op_nodes)[3]);
    static void ApplyBatchModify(NodeStatusModify::NodeBatchContext &ctx, napi_value localObject);
private:
    // C-API RenderNode
    ArkUI_RenderNodeHandle fNodeHandle = nullptr;
    ArkUI_RenderContentModifierHandle fModiferHandle = nullptr;
    ArkUI_ColorPropertyHandle fInvalidateHandle = nullptr;
    
    // 当前系统限制1：无法在Native侧设置ArkTS侧节点属性(setCrcssLanguageOption无法设置未上树节点)
    // 当前系统限制2：FrameNode和RenderNode的clip属性不对齐
    // 当存在外部混排节点时的节点挂载关系，fNodeHandle可以看作当前节点(子树根节点)，用处是设置作用到混排节点上的Clip属性
    // fNodeHandle下面挂载了fExternalRenderNode(从fExternalNode(FrameNode)获取)
    // fExternalNode是在c++侧创建的FrameNode代理节点，目的是设置大小、位置等属性，这个节点下面挂载了混排节点的frameNode
    ArkUI_NodeHandle fExternalNode = nullptr;
    ArkUI_RenderNodeHandle fExternalRenderNode = nullptr;
    
    // used for root node
    void *fCallbackContext = nullptr;
    ArkUI_NodeHandle fCustomNode = nullptr;
    int32_t fRootNodeId = -1;
    bool fNodeIsDrawing = false;
    bool fPendingUnregisterNode = false;
};


#endif //RenderNodeImplC_DEFINED
